package com.tarena.lbs.stock.web.repository;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tarena.lbs.pojo.stock.po.CouponStockPO;
import com.tarena.lbs.stock.web.mapper.CouponStockMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class CouponStockRepository {
    @Autowired
    private CouponStockMapper couponStockMapper;

    public int saveCouponStock(CouponStockPO poParam) {
        return couponStockMapper.insert(poParam);
    }

    public CouponStockPO getCouponStockByCouponId(Integer couponId) {
        QueryWrapper<CouponStockPO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("coupon_id", couponId);
        return couponStockMapper.selectOne(queryWrapper);
    }

    public int updateNumByCouponId(Integer couponId) {
        //直接使用mybatis-plus不容易实现 set num=num-1的sql语句
        //不需要使用映射文件 因为sql不复杂 不需要 动态sql标签
        //直接使用注解写sql
        return couponStockMapper.updateStockByCouponId(couponId);
    }
}
